package com.zhaoguang.car.controller;

import com.zhaoguang.car.common.RespBean;
import com.zhaoguang.car.entity.UserInfo;
import com.zhaoguang.car.service.UserLogRegService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/logreg")
public class UserLogRegController {

    @Autowired
    UserLogRegService userLogRegService;

    @RequestMapping("/register")
    public RespBean register(UserInfo user) {
        System.out.println("账号注册 " + user.getPhone() + " " + user.getUsername() + " " + user.getPassword());
        String msg = userLogRegService.registerUser(user);

        return RespBean.success(msg);
    }

    @RequestMapping("/login")
    public RespBean login(UserInfo user) {
        System.out.println("账号登录 " + user.getPhone() + " " + user.getPassword());
        RespBean resp = userLogRegService.login(user);

        return resp;
    }

    @RequestMapping("/logout")
    public RespBean logout(int userId) {
        System.out.println("用户ID：" + userId);
        RespBean resp = userLogRegService.logout(userId);

        return resp;
    }
}
